/**
 * Created by root on 9/21/16.
 */
function deal(e) {
    $.ajax({
        type: 'GET',
        url: e.id,
        success: function () {
            $(e).parents('li').remove();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest, textStatus, errorThrown);
        }
    })
}

var cg, cp;

function ShowP() {
    var project = $('#project');
    project.children().remove();
    $.each(gmp[cg], function (_, p) {
        var span = document.createElement("button");
        span.id = p;
        span.className = "btn btn-default";
        span.innerHTML = p;
        span.onclick = function () {
            if ($.inArray(cp, gmp[cg]) >= 0) {
                $('#' + cp)[0].className = 'btn btn-default';
            }
            if (cp) {
                $('#task-' + cp).hide();
            }
            this.className = "btn btn-primary";
            cp = this.id;
            $('#task-' + cp).show();
            // $('#result')[0].innerHTML = cg + cp;
        };
        $('#project').append(span);
    });
    var node = project.find('>:first-child')[0];
    node.click();
    cp = node.id;
}

function ShowG() {
    if (gmp.length < 1) {
        $('#result').innerHTML = '<h3>No error.</h3>';
        return
    }

    $.each(gmp, function (g) {
        var span = document.createElement("button");
        span.id = g;
        span.className = "btn btn-default";
        span.innerHTML = g;
        span.onclick = function () {
            if (cg in gmp) {
                $('#' + cg)[0].className = 'btn btn-default';
            }
            this.className = "btn btn-primary";
            cg = this.id;
            ShowP();
        };
        $('#group').append(span);
    });
    var node = $('#group').find('>:first-child')[0];
    node.click();
    cg = node.id;
}
